package cn.kbblog.biz;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.kbblog.activemq.Producer;
import cn.kbblog.activemq.TopicReceiver1;
import cn.kbblog.activemq.TopicSender;
import cn.kbblog.bean.Constant.ActiveMQ_Queue;
import cn.kbblog.bean.Constant.ActiveMQ_Topic;
import cn.kbblog.bean.InfoException;
import cn.kbblog.dao.BaseDao;
import cn.kbblog.dao.UserinfoDao;
import cn.kbblog.entity.Userinfo;

@Service
public class UserinfoBiz extends BaseBiz<Userinfo>{
	@Resource
	private UserinfoDao dao;
	@Resource
	private BaseDao baseDao;
	@Resource
	private Producer producer;
	@Resource
	private TopicSender topicSender;
	
	public void addUserinfo(Userinfo user) throws Exception{
		if(user ==null || ( StringUtils.isBlank(user.getUsername())  && StringUtils.isBlank(user.getPassword()) && StringUtils.isBlank(user.getContent())  )){
			throw new InfoException("保存失败");
		}
		producer.send(ActiveMQ_Queue.test_queue.toString(), JSONObject.toJSONString(user));
//		dao.insert(user);
	}

	public void addTopic(String message) {
		topicSender.send(ActiveMQ_Topic.test_topic.toString(), message);
//		if(TopicReceiver1.num > 0){//模拟并发
//			try {
//				Thread.sleep(300);//耗时操作
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//			
//			TopicReceiver1.num --;
//		}
//		System.out.println("num:"+ TopicReceiver1.num);
	}

	public void getTestpage() {
		String sql = "select * from ";
		baseDao.selectPageByOracle(sql, 6, 50);
		
	}
	
}
